pwmgen: prevent GCC from emitting SSE in base-thread function#3896
pwmgen: prevent GCC from emitting SSE in base-thread function#3896grandixximo wants to merge 1 commit intoLinuxCNC:masterfrom
Conversation
make_pulses() is exported with uses_fp=0 for the base-thread, but GCC
optimizes struct zeroing into SSE instructions (pxor/movups on XMM
registers). Since RTAI skips FPU/SSE save/restore for non-FP threads,
this silently corrupts XMM state of whatever Linux process was running,
causing heap corruption, segfaults, and hard crashes.
Add __attribute__((target("general-regs-only"))) to make_pulses() to
force GCC to use only general-purpose registers.
Confirmed via objdump that the compiled function contains zero SSE
instructions after this change. Tested on RTAI 5.4.280 with the
etch-servo parport config which previously crashed reliably.
See: LinuxCNC#3895
|
Is this fix still needed, or are we going for the meta-fix? |
|
I can work on ripping out non-FP in the weekend, this will not be needed once that is done, it is just a quick fix, if anyone wants to run RTAI with pwmgen in the meantime, Though I doubt there is anyone else but me testing this. |
|
superseded by #3901 |
|
I was about to ask for clarification about this, how do these three PRs fit together? |
|
Oh, this forcibly flagged the pwm step making function to prevented the compiler to use floating point operations in the compiled assembly. The problem was the PWM step making function is usually added to base-thread which has |
make_pulses() is exported with uses_fp=0 for the base-thread, but GCC optimizes struct zeroing into SSE instructions (pxor/movups on XMM registers). Since RTAI skips FPU/SSE save/restore for non-FP threads, this silently corrupts XMM state of whatever Linux process was running, causing heap corruption, segfaults, and hard crashes.
Add attribute((target("general-regs-only"))) to make_pulses() to force GCC to use only general-purpose registers.
Confirmed via objdump that the compiled function contains zero SSE instructions after this change. Tested on RTAI 5.4.280 with the etch-servo parport config which previously crashed reliably.
See: #3895